﻿using Crgd.UAuthServer.T4.Entities;
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace Crgd.UAuthServer.T4.Helpers
{
    /// <summary>
    /// 枚举信息构建辅助类
    /// </summary>
    public class EnumInfoHelper
    {
        /// <summary>
        /// 根据数据库列数据信息构建枚举类型信息
        /// </summary>
        /// <param name="column">类数据</param>
        /// <returns></returns>
        public EnumInfo BuildEnumInfo(DbColumn column)
        {
            if (string.IsNullOrEmpty(column.EnumTypeString))
            {
                return null;
            }

            return new EnumInfo(column.EnumTypeString, column.Remark);
        }

        /// <summary>
        /// 根据数据表数据信息构建该表所有的枚举类型信息
        /// </summary>
        /// <param name="table"></param>
        /// <returns></returns>
        public IList<EnumInfo> BuildEnumInfo(DbTable table)
        {
            return 
                table.Columns
                    .Where(p => !string.IsNullOrEmpty(p.EnumTypeString))
                    .Select(p => new EnumInfo(p.EnumTypeString, p.Remark)).ToList();
        }
    }
}
